package com.bootdo.system.service.impl;

import com.bootdo.system.dao.FrontuserDao;
import com.bootdo.system.domain.FrontuserDO;
import com.bootdo.system.service.FrontuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.concurrent.RecursiveTask;


@Service
public class FrontuserServiceImpl implements FrontuserService {
    @Autowired
    private FrontuserDao frontuserDao;

    @Override
    public FrontuserDO get(Long userid) {
        return frontuserDao.get(userid);
    }

    @Override
    public FrontuserDO getUserBytransferer(Integer transferer) {
        return frontuserDao.getUserBytransferer(transferer);
    }

    @Override
    public List<FrontuserDO> list(Map<String, Object> map) {
        return frontuserDao.list(map);
    }

    @Override
    public int count(Map<String, Object> map) {
        return frontuserDao.count(map);
    }

    @Override
    public int save(FrontuserDO frontuser) {
        return frontuserDao.save(frontuser);
    }

    @Override
    @Transactional
    public int update(FrontuserDO frontuser) {
        return frontuserDao.update(frontuser);
    }

    @Override
    public int remove(Long userid) {
        return frontuserDao.remove(userid);
    }

    @Override
    public int batchRemove(Long[] userids) {
        return frontuserDao.batchRemove(userids);
    }

    @Override
    public FrontuserDO login(String username, String password) {

        return frontuserDao.login(username, password);
    }

    @Override
    public FrontuserDO getUserByPassword(String loginpass) {
        return frontuserDao.getUserByPassword(loginpass);
    }

    @Override
    public FrontuserDO getUserByUsername(String username) {
        return frontuserDao.getUserByUsername(username);
    }

    @Override
    public FrontuserDO getUserByyaoqingma(String yaoqingma) {
        return frontuserDao.getUserByyaoqingma(yaoqingma);
    }

    @Override
    public FrontuserDO getUserByUsernameAndPhone(String username, String phone) {

        return frontuserDao.getUserByUsernameAndPhone(username, phone);
    }

    @Override
    public void updateTimejian1() {
        frontuserDao.updateTimejian1();
    }

    @Override
    public List<FrontuserDO> getUserZhituiList(Long userid) {


        return frontuserDao.getUserZhituiList(userid);
    }

    @Override
    public List<FrontuserDO> getUserShequiList(Long userid, List<FrontuserDO> result) {

        //查询每一层的人
        List<FrontuserDO> userZhituiList = getUserZhituiList(userid);

        if (userZhituiList != null && userZhituiList.size() > 0) {
            //查询下一层
            for (FrontuserDO user : userZhituiList) {
                getUserShequiList(user.getUserid(), result);
            }
        }
        result.addAll(userZhituiList);

        return result;


    }

    @Override
    public void updateByUserIdAndpId(FrontuserDO frontuserDO) {
        frontuserDao.updateByUserIdAndpId( frontuserDO);
    }

    @Override
    public void UpdateZichanByAcccuntID(Long transferer, BigDecimal transactAmt) {
        frontuserDao.UpdateZichanByAcccuntID( transferer,  transactAmt);
    }

    @Override
    public boolean judgeUser(Long userid) {

        FrontuserDO user = get(userid);
        if(user.getYouxiaotime()<=0||user.getZichan().compareTo(BigDecimal.TEN)<0){

             return  false;
        }

        if(user.getHuobiapikey()==null||user.getHuobiapikey().trim().equals("")){

            return false;
        }

        if(user.getHuobiapisecret()==null||user.getHuobiapisecret().trim().equals("")){

            return false;
        }

        //System.out.println("有效用户 "+user.getUsername());

        return true;
    }

    @Override
    public List<FrontuserDO> userListOrderId() {

        return frontuserDao.userListOrderId();
    }

}
